package activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.ci_edit.R;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import model.Constants;
import okhttp3.Call;

/**
 * Created by Administrator on 2017/7/23.
 */

public class FeedbackActivity extends BaseActivity {
    private EditText mEmailAddress, mAdvices;
    private Button submit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);

        mEmailAddress = (EditText) findViewById(R.id.emailAddrFeedback);
        mAdvices = (EditText) findViewById(R.id.advicesEdit);
        submit = (Button) findViewById(R.id.submitAdvices);

        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String address = mEmailAddress.getText().toString();
                String advices = mAdvices.getText().toString();
                if (address.length() <= 0) {
                    Toast.makeText(FeedbackActivity.this, "请输入邮箱", Toast.LENGTH_SHORT).show();
                } else if (advices.length() <= 0) {
                    Toast.makeText(FeedbackActivity.this, "请输入您的意见或建议", Toast.LENGTH_SHORT).show();
                } else {
                    OkHttpUtils.post()
                            .url(Constants.SERVER_URL + "login")
                            .addParams("username", address)
                            .addParams("advices", advices)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Call call, Exception e, int id) {

                                }

                                @Override
                                public void onResponse(String response, int id) {
                                    if (response.equals("EMAIL_SUCCESS")) {
                                        Toast.makeText(FeedbackActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
                                    } else {
                                        Toast.makeText(FeedbackActivity.this, "提交失败", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                }
            }
        });
    }
}
